package com.suray.attendance.db.utils;


import com.suray.attendance.common.utils.LoggerUtil;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

/**
 * Description: 宜搭的表单数据创建时间从String类型转换为LocalDateTime
 * Author: linyu
 * Date: 2023/10/19
 */
public class StringToLocalDateTime {

    public static LocalDateTime convert(String createTimeGMT){
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
        Date date = null;
        try {
            date = dateFormat.parse(createTimeGMT);
            // 转化为LocalDateTime
            LocalDateTime localDateTime = date.toInstant().atZone(ZoneId.of("UTC")).toLocalDateTime();
            return localDateTime;
        } catch (ParseException e) {
            LoggerUtil.error("宜搭的表单数据创建时间从String类型转换为LocalDateTime失败,异常信息为"+e.getMessage(),StringToLocalDateTime.class);
            e.printStackTrace();
        }
        return null;
    }
}
